<?php

class Qtadmin_MenuController extends Zend_Controller_Action
{

    public function init()
    {
        include_once 'in.php';
        
        //Khai bao su dung Layout
        $op = array(
                    'layout' => 'layout',
                    'layoutPath' =>"./public/qtadmin/"
                    );
        Zend_Layout::startMVC($op);
        
        
    }

    public function indexAction()
    {
        $m = new Qtadmin_Model_Menu;
        $this->view->menu = $m->getOn();
    }
    
    public function getoffAction()
    {
        $m = new Qtadmin_Model_Menu;
        $this->view->menu = $m->getOff();
        //Dong nay` ko cho no do layout nek`
        //$this->_helper->layout->disableLayout();
    }
    
    public function getallAction()
    {
        $m = new Qtadmin_Model_Menu;
        $this->view->menu = $m->getAll();
    }
    
    public function addAction()
    {
        if($this->_request->isPost())//Khi form dk nhan submit
        {
            //Xy ly them menu
            $params = $this->_request->getParams();//Lay het du lieu
            $check = new Qtadmin_Form_Valid_Addmenu($params);//Kiem tra du lieu
            if($check->Valid() == false)   
                $this->view->error = $check->messages;//Dua thong bao ra view
            else//Neu oki thi` add du lieu
            {
                $up = new Qtadmin_Model_Menu;
                $data = array(
                            'name'=>$params['name'],
                            'title'=>$params['title'],
                            'active'=>1);
                $up->qtInsert($data);
                $this->_redirect('/qtadmin/menu');
            }
        }
        else{
            //Dong nay` ko cho no do layout nek`
        
        }
        
    }
    
    public function qtdeleteAction()
    {
        $id = $this->_request->getParam('id');
        $id = intval($id);
        $m = new Qtadmin_Model_Menu;
        $m->qtDelete("menu_id = $id");
        $this->_redirect($_SERVER['HTTP_REFERER']);//truy cai duong dan di den de ve cho hop ly hehe
    }
    
    public function offactiveAction()
    {
        $id = $this->_request->getParam('id');
        $id = intval($id);
        $m = new Qtadmin_Model_Menu;
        $m->offActive($id);
        $this->_redirect($_SERVER['HTTP_REFERER']);//truy cai duong dan di den de ve cho hop ly hehe
    }
    
    public function onactiveAction()
    {
        $id = $this->_request->getParam('id');
        $id = intval($id);
        $m = new Qtadmin_Model_Menu;
        $m->onActive($id);
        $this->_redirect($_SERVER['HTTP_REFERER']);//truy cai duong dan di den de ve cho hop ly hehe
    }
    

    
   
    
    


}



